package com._51cto.healthy.service;

import com._51cto.healthy.base.BaseMapper;
import com._51cto.healthy.content.P;
import com._51cto.healthy.mapper.SportMapper;
import com._51cto.healthy.pojo.Sport;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SportServiceImpl implements SportService{
    @Autowired
    private SportMapper sportMapper;
    @Override
    public BaseMapper<Sport> getDao() {
        return sportMapper;
    }

    //查询运动列表
    @Override
    public P<Sport> findAll(String query, Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        List<Sport> sportList = sportMapper.findAll(query);
        PageInfo pageInfo=new PageInfo(sportList);

        return new P<Sport>().setRows(pageInfo.getList())
                .setPageNum(pageInfo.getPageNum())
                .setPages(pageInfo.getPages())
                .setPageSize(pageInfo.getPageSize())
                .setTotal(pageInfo.getTotal());
    }

    @Override
    public void deleteByPK(Integer pk) {
        sportMapper.deleteByPK(pk);
    }

    @Override
    public List<Sport> searchByName(String query) {
        return sportMapper.findByname(query);
    }
}
